home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2005 January / My Disc.iso / patch / Zoo Tycoon 2 / zoo2patch.exe / x001_000.z2f / scenario / scripts / challenge / money / ventureloan.lua < prev   
Encoding:
Text File  |  2004-11-12  |  4.7 KB  |  178 lines

  1. -- ventureloan.lua
  2. -- functions for the ventureloan challenge
  3.  
  4. include "scenario/scripts/ui.lua";
  5. include "scenario/scripts/entity.lua";
  6. include "scenario/scripts/economy.lua";
  7. include "scenario/scripts/misc.lua";
  8.  
  9. function validate()
  10.     BFLOG(SYSTRACE, "ventureloan validate");
  11.     
  12.     local donealready = getglobalvar("ventureloan_over");
  13.     if (donealready == nil) or (donealready ~= "true") then
  14.         BFLOG(SYSTRACE, "Giving ventureloan challenge");
  15.         local mgr = queryObject("BFScenarioMgr");
  16.         if (mgr) then
  17.             mgr:BFS_ADDSCENARIO("scenario/goals/challenge/ventureloan.xml");
  18.         end
  19.  
  20.         return 1;
  21.     end
  22.     
  23.     return 0;
  24. end
  25.  
  26.  
  27. -- gives you venture capitalist loan challenge
  28. function evalventureloan(comp)
  29.  
  30.     BFLOG(SYSTRACE, "evalventureloan");
  31.  
  32.     challenge = getglobalvar("challenge")
  33.     if (challenge == "accept") then
  34.         BFLOG(SYSTRACE, "*******You accepted!")
  35.         local mgr = queryObject("BFScenarioMgr");
  36.         if (mgr) then
  37.             mgr:BFS_SHOWRULE("ventureloan");
  38.         end
  39.         
  40.         --[[
  41.         setglobalvar("challengeactive", "true");
  42.         setglobalvar("challenge", nil);
  43.         --]]
  44.         
  45.         setchallengeactive();
  46.         
  47.         -- INIT THE LOAN
  48.         if comp.loanactive == nil then
  49.             -- Initialize the loan info
  50.             comp.loanactive = 1;
  51.             comp.loanpayback = 12000;
  52.             comp.loanskim = .4;
  53.             comp.loanmonth = getCurrentMonth();
  54.             comp.prevMonthPaid = 0;
  55.             
  56.             -- Get the starting donations
  57.             comp.prevDonations = getDonationsAllAnimals() + getDonations("Education");
  58.  
  59.             BFLOG(SYSTRACE, "Loan initialized - size: 10000  payback: "..comp.loanpayback.." skim: "..comp.loanskim..".");
  60.  
  61.             -- Give them their money
  62.             giveCash(10000);    
  63.         end
  64.         
  65.         comp.accept = 1;
  66.         
  67.     elseif (challenge == "decline") then
  68.         BFLOG(SYSTRACE, "You declined!");
  69.         --setglobalvar("challenge", nil);
  70.         
  71.         --setglobalvar("ventureloan_over", "true");
  72.         return -1;
  73.     end        
  74.     
  75.     if comp.accept == nil then
  76.         if (challenge == nil) then
  77.             local showchallengepanel = showchallengepanel("Challengetext:CHgrantmoney2");
  78.             BFLOG(SYSTRACE, "I'm waiting for you to click accept or decline!");
  79.             setglobalvar("challenge", "waiting");
  80.         end    
  81.     end
  82.  
  83.     if comp.accept == 1 then
  84.         
  85.         -- MAINTAIN THE LOAN
  86.         
  87.         BFLOG(SYSTRACE, "Checking loan...");
  88.         -- Only if they currently have a loan
  89.         if comp.loanactive ~= nil then
  90.             local curMonth = getCurrentMonth();
  91.             
  92.             BFLOG(SYSTRACE, "Last loan month: "..comp.loanmonth.." current month: "..curMonth..".");
  93.     
  94.     
  95.             -- Only take the cash if they haven't paid everything back
  96.             if (comp.loanpayback > 0) then
  97.                 -- Find any new donations and subtract them from the total
  98.                 local currentDonations = getDonationsAllAnimals() + getDonations("Education");
  99.                 local skimamount = (currentDonations - comp.prevDonations) * comp.loanskim;
  100.                 comp.prevDonations = currentDonations;
  101.                 comp.prevMonthPaid = comp.prevMonthPaid + skimamount;
  102.                 comp.loanpayback = comp.loanpayback - skimamount;
  103.             
  104.                 BFLOG(SYSNOTE, "Skim: "..skimamount.."  MonthTotal: "..comp.prevMonthPaid.."  LoanBalance: "..comp.loanpayback);
  105.             
  106.                 -- Subtract this skim from their cash and loan payback
  107.                 takeCashNoPopup(skimamount);
  108.             end
  109.  
  110.             -- If we have a new month to process
  111.             if (curMonth > comp.loanmonth) then
  112.                 -- If they have paid back their fair share
  113.                 if comp.loanpayback < 0 then
  114.  
  115.                     -- Give them back the overpay
  116.                     local overpay = 0 - comp.loanpayback;
  117.                     giveCashNoPopup(overpay);
  118.  
  119.                     -- Now cancel the loan
  120.                     comp.loanactive = nil;
  121.                     BFLOG(SYSTRACE, "Loan has been completely repaid!");
  122.                 
  123.                     return 1;
  124.                 end
  125.                 if(comp.prevMonthPaid ~= 0)then
  126.                     showgivecash("Challengetext:GenericMoneyLoss", (0 - comp.prevMonthPaid));
  127.                 end
  128.                 comp.prevMonthPaid = 0;
  129.                 -- If it's not paid off yet, then update the month
  130.                 comp.loanmonth = curMonth;
  131.             end
  132.         end
  133.     end
  134.     
  135.     return 0;
  136. end
  137.  
  138.  
  139. function completeventureloan(comp)
  140.  
  141.     BFLOG(SYSTRACE, "WE DID IT");
  142.     
  143.     showchallengewin("Challengetext:CHgrantmoney2Success");
  144.     
  145.     resetchallengeoverandcomplete("ventureloan");
  146.     
  147.     incrementglobalchallenges();
  148.     
  149.     --[[
  150.     setglobalvar("challengeactive", "false");
  151.     
  152.     -- Don't hit this challenge again.
  153.     setglobalvar("ventureloan_over", "true");
  154.     
  155.     -- Increment the number of challenges completed
  156.     local num = getglobalvar("numchallcomplete");
  157.     if (num == nil) then
  158.         num = 0;
  159.     end
  160.     local newnum = tonumber(num) + 1;
  161.     BFLOG(SYSTRACE, "Setting number of challenges complete to: "..newnum..".");
  162.     setglobalvar("numchallcomplete", tostring(newnum));
  163.     --]]
  164.  
  165. end
  166.  
  167. function failventureloan(comp)
  168.     BFLOG(SYSTRACE, "DECLINED");
  169.     
  170.     resetchallengeover("ventureloan");    
  171.     
  172.     --[[
  173.     setglobalvar("challengeactive", "false");
  174.     
  175.     -- Don't hit this challenge again.
  176.     setglobalvar("ventureloan_over", "true");
  177.     --]]
  178. end